<?php
ob_start();
session_start();


function __autoload($class_name) {
include './rest/data/'.$class_name . '.php';
}


$cart = $_SESSION['cart'];
$count = null;
if(is_null($cart) || $cart -> countOrder()< 1){
header( 'Location:index.php' ) ;
}
$count =$cart -> countOrder(); 
$orderList = $cart -> getOrderList();
$total_price=0;


?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Merchandise :: Hambaa.com</title>
<link rel="stylesheet" type="text/css" href="jquery-ui.css" />
<link rel="stylesheet" type="text/css" href="styles/Graphitti_style.css" />
<script type="text/javascript" src="jquery.min.js"></script>
	<script src="jquery.ui.core.js"></script>
	<script src="jquery.ui.widget.js"></script>
	<script src="jquery.ui.position.js"></script>
	<script src="jquery.ui.menu.js"></script>
	<script src="jquery.ui.autocomplete.js"></script>
<script>
$(document).ready(function(){
		 $.ajax({url:"rest/data/readStates.php",
		type:'GET',
		success:function(result){
		var availableStates=[];
			//alert(result);
		availableStates = result.split(",");
		$( "#buyer_state" ).autocomplete({
			source: function(req, response) { 
				var re = $.ui.autocomplete.escapeRegex(req.term); 
				var matcher = new RegExp( "^" + re, "i" ); 
				response($.grep( availableStates, function(item){ 
				return matcher.test(item); }) ); 
			},
			minLength:1
		});
		},
		error:function(result){
			alert("error");
		}
		});
		
$("#buyer_state").blur(function(){
	var buyerState=document.getElementById('buyer_state').value;		 	
	$.ajax({url:"rest/data/readCities.php",
		data :{buyerState:buyerState},
		type:'GET',
		success:function(result){
		var availableCities=[];
		availableCities = result.split(",");
		$( "#buyer_city" ).autocomplete({
			source: function(req, response) { 
				var re = $.ui.autocomplete.escapeRegex(req.term); 
				var matcher = new RegExp( "^" + re, "i" ); 
				response($.grep( availableCities, function(item){ 
				return matcher.test(item); }) ); 
			},
			minLength:1
		});
		},
		error:function(result){
			alert("error");
		}
		});
});		

$("#buyer_state").blur(function(){
	if($(this).val().trim() == ""){
		$("#buyer_city").val("");
	}	
});	



$("#saveorder").click(function(){
var buyerFirstname=document.getElementById('buyer_firstname').value;		 	
var buyerLastname=document.getElementById('buyer_lastname').value;		 	
var buyerAddress1=document.getElementById('buyer_address1').value;		 	
var buyerAddress2=document.getElementById('buyer_address2').value;		 	
var buyerCity=document.getElementById('buyer_city').value;		 	
var buyerState=document.getElementById('buyer_state').value;		 	
var buyerPincode=document.getElementById('buyer_pincode').value;		 	
var buyerEmail=document.getElementById('buyer_email').value;		 	
var buyerContactno=document.getElementById('buyer_contactno').value;

if(validate('alpha','buyer_firstname') && 
	validate('alpha','buyer_lastname') &&
	validate('address','buyer_address1') &&
	validate('alpha','buyer_city') &&
	validate('alpha','buyer_state') &&
	validate('pin','buyer_pincode') &&
	validate('email','buyer_email') &&
	validate('mobile','buyer_contactno')){
	
	}else{
	return;
	}

//alert(buyerContactno);	 	
$.ajax({url:"rest/data/saveorder.php",
type:'GET',
data : {buyerFirstname:buyerFirstname,buyerLastname:buyerLastname,buyerAddress1:buyerAddress1,buyerAddress2:buyerAddress2,buyerCity:buyerCity,buyerState:buyerState,buyerPincode:buyerPincode,buyerEmail:buyerEmail,buyerContactno:buyerContactno},
success:function(result){
	//alert(result);
document.getElementById('shippingAddress').style.display = "none";	

document.getElementById('orderConfirmation').style.display = "block";	
	
	var address=buyerFirstname+' '+buyerLastname+'<br>'+buyerAddress1+'<br>Landmark :'+buyerAddress2+'<br>'+buyerCity+'<br>'+buyerState+' '+buyerPincode;
$("#address").html(address);

$("#orderNo").html(result);

$("#email").html(buyerEmail);
document.getElementById('pdforderid').value=result;
document.getElementById('pdfemail').value=document.getElementById('buyer_email').value;

},
error:function(result){
	alert("error");
}
});
});
});

function submitform(){
	//alert('hi');
	var formId = document.getElementById('generatePdf');
	formId.action = 'order_summary_pdf.php';
	formId.submit();	

}

function validate(type,testValue){
var emailRegex =/^([0-9a-zA-Z]+([_.-]?[0-9a-zA-Z]+)*@[0-9a-zA-Z]+[0-9,a-z,A-Z,.,-]*(.){1}[a-zA-Z]{2,4})+$/g;
var mobileRegex =/^[0-9]\d{9}$/g;
var alphaRegex =/^[A-Za-z ]+$/g; 
var addressRegex = /^[^ ][^]+$/g;
var pinRegex =/^[0-9]\d{5}$/g;
var text=document.getElementById(testValue).value;
var idforDisplay = document.getElementById(testValue+'display');
if(type == 'alpha' ){
type=alphaRegex;
}else if (type == 'pin'){
type=pinRegex;
}else if (type == 'address'){
type=addressRegex;
}else if (type == 'mobile'){
type=mobileRegex;
}else{
type=emailRegex;
}
if(type.test(text))
{
idforDisplay.style.visibility="hidden";
return true;
}else {
idforDisplay.style.visibility="visible";
return false;
}
}

$(function() {

		
	});
	
	

</script>

</head>

<body>
<table id="containertable" cellpadding="0" cellspacing="0" border="0" width="950" align="center" >
<tr>
<td align="right">
	<div id="menulinks">
   
    <a href="index.php" class="active">Home</a>
    <a href="offers.php">Offers</a>
	<a href="about_us.php">About Us</a>
	<a href="contact_us.php">Contact Us</a>
    
    </div>

</td>
</tr>

</table>



<table  border="0" align="center" width="952" height="118" background="images/round_back1.png"  >
<tr >
<td width="121" height="114" align="right" valign="bottom">

<a href="index.php"><img src="images/logopng.png" width="103" height="99" /></a></td>
<td width="819" align="left" valign="top">
<a href="index.php"><img src="images/hambaa_logo_newjpg.jpg" width="308" height="107" /></a>
</td>

</tr>
</table>

<table id="outertable" border="0" width="950" height="269" align="center" bgcolor="#FFFFFF" cellpadding="5" >

<tr >
<td width="280" align="center" valign="top">
	<div id="table_container" style="overflow:auto;height:300px;" >            
	<table id="innerleft" border="0" cellspacing="5" bgcolor="#CCCCCC">
    <tr><td colspan="4"><h3>&nbsp; Order Summary</h3></td></tr>
    <?php
    for ($i = 0; $i < $count; $i++) {
			$myOrder = $orderList[$i];
	?>
    <tr><td><img  src="images/tshirts/ts<?php echo $myOrder->getProductId();?>.jpg" height="60" width="60">	</td>
    <td>X <?php echo $myOrder->getQuantity();?></td>
    <td><?php echo $myOrder->getProductName();?></td>
    <td>= <?php echo $myOrder->getRate()*$myOrder->getQuantity();?></td>
    </tr>
    
    <?php 
	$total_price+=$myOrder->getRate()*$myOrder->getQuantity();
	} 
	?>
    <tr><td colspan="4"><hr></tr>
    <tr><td colspan="2"><h3>&nbsp; Total</h3></td><td colspan="2"><h4><?php echo $total_price;?></h4></td></tr>
    </table>
	</div>


</td>
<td width="9" valign="top"><img src="images/vr.png" /></td>
<td width="585" align="center" valign="top">
<div id="shippingAddress" style="display:block">

<h1>Shipping Address &amp; Contact Details</h1>
<br />
	<table id="innerright" border="0" cellpadding="0" width="100%">
    


        <tr>
		<td width="16%">First Name: </td><td width="26%"><input type="text" name="buyer_firstname" id="buyer_firstname" onkeyup="validate('alpha','buyer_firstname')" /></td>
		<td width="6%"><img src="images/cross.png" style="visibility:hidden;height:15px;width:15px;" id="buyer_firstnamedisplay"/></td>
		<td width="4%" rowspan="5" align="left"><img src="images/separator_checkout.png" /></td>
		<td width="16%">Last Name: </td><td width="26%"><input type="text" name="buyer_lastname" id="buyer_lastname" onkeyup="validate('alpha','buyer_lastname')"/>
		<td width="6%"><img src="images/cross.png" style="visibility:hidden;height:15px;width:15px;" id="buyer_lastnamedisplay"/></td>
		</tr>
        <tr>
		<td>Address : </td><td><input type="text" id="buyer_address1" onkeyup="validate('address','buyer_address1')"/></td>
		<td width="6%"><img src="images/cross.png" style="visibility:hidden;height:15px;width:15px;" id="buyer_address1display"/></td>
        <td>Landmark : </td><td><input type="text" id="buyer_address2"/></td>
		<td width="6%"><img src="images/cross.png" style="visibility:hidden;height:15px;width:15px;" id="buyer_address2display"/></td>
		</tr>
        <tr>
		<div class="ui-widget"><td>State : </td><td><input type="text" id="buyer_state" onkeyup="validate('alpha','buyer_state')" /></td></div>
		<td width="6%"><img src="images/cross.png" style="visibility:hidden;height:15px;width:15px;" id="buyer_statedisplay"/></td>
		<div class="ui-widget"><td>City : </td><td><input type="text" id="buyer_city" onkeyup="validate('alpha','buyer_city')"/></td></div>
		<td width="6%"><img src="images/cross.png" style="visibility:hidden;height:15px;width:15px;" id="buyer_citydisplay"/></td>
		</tr>
        <tr>
		<td>Pincode : </td><td><input type="text" maxlength="6" id="buyer_pincode" onkeyup="validate('pin','buyer_pincode')"/></td>
		<td width="6%"><img src="images/cross.png" style="visibility:hidden;height:15px;width:15px;" id="buyer_pincodedisplay"/></td>
		<td>e-mail: </td><td><input type="text" id="buyer_email" onkeyup="validate('email','buyer_email')"/></td>
		<td width="6%"><img src="images/cross.png" style="visibility:hidden;height:15px;width:15px;" id="buyer_emaildisplay"/></td>
		</tr>
        <tr><td>Contact No: </td><td>+91 <input type="text" maxlength="10" size="15" id="buyer_contactno" onkeyup="validate('mobile','buyer_contactno')"/></td>
		<td width="6%"><img src="images/cross.png" style="visibility:hidden;height:15px;width:15px;" id="buyer_contactnodisplay"/></td>
		<td colspan="3" align="center"><a href = "#" id="saveorder" class="wishbtn" >Save Order</a></td>
</tr>
     </table>
   <br />
   <h3>Please review your order summary before checking out</h3>
   

</div>   
<div id="orderConfirmation" style="display:none">

<h1>Order Confirmation</h1>

	<table id="innerright" border="0" cellspacing="5" width="100%" >
    
		
        <tr>
        	<td><h3>&nbsp; Shipping Address &nbsp; </h3></td>
            <td>   <h4>Your order is succesfully saved</h4></td>
         </tr>
        <tr><td>
        </td></tr>    
            
        <tr valign="top">
        	<td>
            
            <div  id="address"></div>
                   
            </td>
        	<td>
            Your order no is <span id="orderNo" style="background-color:#0099CC;  padding:5px"></span>. Please note it for future reference<br><br>
            A confirmation mail has been sent to : <span id="email"></span><br><br>
            <a href="#" onclick="submitform()"><span style="background-color:#0099CC;  padding:5px">click here</span></a> to download your order copy in pdf format 
            </td>
        </tr>
        <tr><td colspan="2" align="center"><br><h3>Thank you for chosing hambaa!</h3>
</td></tr>
       
     </table>
    
<table>
     <tr><td colspan="2"><br />
<a href="suggest.php"><span style="background-color:#0099CC;  padding:5px">Attend a small survey</span></a></td></tr>
 
</table>
 
</div>


   
</td>

</tr>
</table>

<table width="952" align="center" border="0" background="images/round_back2.png" height="58" >
<tr>
<td align="right" valign="top">   
<span style="color:#F00;text-align:left">*Payment Mode: Cash On Delivery&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
</td>
</tr>

</table>

<br>

<div id="footer" > 


<table border="0" width="952" height=154 align="center" >
<tr>
<td >
<h1>My Hambaa</h1>
</td>
<td >
<h1>Shopping Policies</h1>
</td>
<td >
<h1>Payment Information</h1>
</td>
<td >
<h1>Contact Us</h1>
</td>
</tr>

<tr>
<td>
<a href = "javascript:void(0)" onclick = "document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block';getShoppingCart1()">My Cart</a> |
<a href="about_us.php">My Order</a> |
<a href="about_us.php">FAQs</a>
</td>

<td >
<a href="about_us.php">Return Policy</a> |
<a href="about_us.php">Refund Policy</a> |
<a href="about_us.php">Terms and Conditions</a>
</td>

<td >
<a href="about_us.php">Payment Options: </a>COD
</td>

<td >
e-mail:
<a href="mailto:care@hambaa.com">care@hambaa.com</a>
</td>
</tr>

<tr align="center"><td colspan="4">
<hr />
&copy;2012 All Rights Reserved by <a href="index.php">www.hambaa.com</a>
</td></tr>
</table>
</div>
<form id="generatePdf" method="POST" target="_blank" >
<input type="text" id="pdfemail" name="pdfemail" />
<input type="text" id="pdforderid" name="pdforderid" />
</form>

</body>
</html>
<?php 
ob_end_flush();
?>

